//
//  AyNavigationController.m
//  xWeibo
//
//  Created by alvis mac on 8/4/15.
//  Copyright (c) 2015 alvis. All rights reserved.
//

#import "AyNavigationController.h"
#import "AyDefine.h"
#import "UIImageExtend.h"
#import "UIBarButtonItemExtend.h"
@interface AyNavigationController ()

@end

@implementation AyNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if (iOS7) {
        // 重新拥有滑动出栈的功能
        self.interactivePopGestureRecognizer.delegate = nil;
    }
}



+ (void)initialize{

    [self setupNavBarTheme];
    
    [self setupBarButtonItemTheme];
}



+ (void)setupNavBarTheme
{
    UINavigationBar *navBar=[UINavigationBar appearance];
    if (!iOS7) {
        [navBar setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
    
    NSMutableDictionary *textAttrs=[NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName]=[UIColor blackColor];
    NSShadow *shadow=[[NSShadow alloc] init];
    shadow.shadowOffset=CGSizeZero;
    textAttrs[NSShadowAttributeName] = shadow;
    textAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:19];
    [navBar setTitleTextAttributes:textAttrs];
}


+ (void)setupBarButtonItemTheme
{
    UIBarButtonItem *item = [UIBarButtonItem appearance];

    if (!iOS7) {
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
        [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
    }
    
 
   
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = iOS7 ? [UIColor orangeColor] : [UIColor grayColor];
    NSShadow *shadow=[[NSShadow alloc] init];
    shadow.shadowOffset=CGSizeZero;
    textAttrs[NSShadowAttributeName] = shadow;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:iOS7 ? 14 : 12];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count>0) {
        viewController.hidesBottomBarWhenPushed=YES;
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"navigationbar_back" highIcon:@"navigationbar_back_highlighted" target:self action:@selector(back)];
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"navigationbar_more" highIcon:@"navigationbar_more_highlighted" target:self action:@selector(more)];
    }
    [super pushViewController:viewController animated:animated];
}


- (void)back
{
    [self popViewControllerAnimated:YES];
}


- (void)more
{
    [self popToRootViewControllerAnimated:YES];
}

@end
